<template>
	<view class=" padding-bottom-xl">
		<view class="bg-white padding margin-bottom-sm" v-for="v in list">
			<view class="flex justify-between" style=" align-items: center;">
				<view class="flex margin-tb">
					<image class="cu-avatar round margin-right" src="../../../../static/lsq/金刚区-09.png"></image>
					<view>
						<view class="text-lg">{{v.name}} {{v.phone}}</view>
						<view class="margin-top-sm text-gray">{{v.address}}{{v.remark}}</view>
					</view>
				</view>
				<view class="cuIcon-edit" @click="goto('/pages/my/set/address/add?id=' + v.id)"></view>
			</view>
			<view class="padding-tb-xs flex" style="border-top: 1px dashed #d0d0ce;">
				<text class="text-left text-orange" style="margin-right: auto;">{{v.mr == 1 ? "使用中" : ""}}</text>
				<button class="cuIcon-copy round bg-orange cu-btn sm margin-right-sm" @click="useClick(v)">使用该地址</button>
				<button class="cuIcon-delete round bg-red cu-btn sm" @click="delClick(v)">删除</button>
			</view>
		</view>
		
		<view class="myBar cu-bar bg-white tabbar border shop" style="position: fixed; width: 750rpx; bottom: 0;">
			<view style="width: 50%;" class="padding-lr text-lg text-bold">
				<!-- <text>应付金额：</text>
				<text class="text-red">￥152</text> -->
			</view>
			<view  class="bg-red submit cuIcon-add round padding-lr" @click="goto('/pages/my/set/address/add')">添加收货地址</view>
		</view>
	</view>
</template>

<script>
	import addressApi from "../../../../api/new/addressApi.js"
	export default{
		data() {
			return {
				list: [{}]
			}
		},
		onLoad() {
			// this.init()
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				addressApi.addressList().then(res => {
					this.list = res.rows
				})
			},
			useClick(row) {
				row.mr = 1
				addressApi.editAddress(row).then(res => {
					this.init()
				})
			},
			delClick(row) {
				uni.showModal({
					title:"是否删除",
					content:"是否删除该地址？",
					success: (res) => {
						if (res.confirm) {
							addressApi.delAddress({ids: row.id}).then(res => {
								this.init()
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
</style>